package com.myres.struts2.action;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.myres.dao.OrderDao;
import com.myres.dao.ShopDao;
import com.myres.dao.UserDao;
import com.myres.model.Order;
import com.myres.model.Shop;
import com.myres.model.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class GetOrderAction extends ActionSupport {
	private UserDao userDao;
	private OrderDao orderDao;
	private int page=0;
	private int pageCount=20;
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	private ShopDao shopDao;
	private Set<Order> orders;
	private List<Order> myOrders;

	public OrderDao getOrderDao() {
		return orderDao;
	}
	public void setOrderDao(OrderDao orderDao) {
		this.orderDao = orderDao;
	}
	public List<Order> getMyOrders() {
		return myOrders;
	}
	public void setMyOrders(List<Order> myOrders) {
		this.myOrders = myOrders;
	}
	public Set<Order> getOrders() {
		return orders;
	}
	public void setOrders(Set<Order> orders) {
		this.orders = orders;
	}
	public ShopDao getShopDao() {
		return shopDao;
	}
	public void setShopDao(ShopDao shopDao) {
		this.shopDao = shopDao;
	}
	/**
	 * @return
	 */
	public String execute() {
		// TODO Auto-generated method stub
		User user =(User) ActionContext.getContext().getSession().get("user");
		user =userDao.get(user.getId());
		Set<Shop> shops = user.getShops();
		Iterator<Shop> iter = shops.iterator();
		Shop shop = iter.next();
		this.orders = shop.getOrders();
		System.out.println("order size="+orders.size());
		return SUCCESS;
	}
	private int shopId;
	private int status;
	public int getShopId() {
		return shopId;
	}
	public void setShopId(int shopId) {
		this.shopId = shopId;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getOrderOfShop(){
		 User user =(User) ActionContext.getContext().getSession().get("user");
		user =userDao.get(user.getId());
		Set<Shop> shops = user.getShops();
		Iterator<Shop> iter = shops.iterator();
		Shop shop = iter.next();
		this.myOrders = orderDao.findByStatusInRangeOfShop(shop.getId(), status, page*pageCount, pageCount);
		System.out.println("my order size="+myOrders.size());
		return SUCCESS;
	}
}